export const formatTime = (time) => {
  return time.replace(/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/, "$1-$2-$3 $4:$5:$6");
}


export function formatTimeDifference(inputTime) {
  const now = new Date();
  const inputDate = new Date(inputTime);
  const differenceInSeconds = Math.floor((now - inputDate) / 1000);
  
  if (differenceInSeconds < 60) {
      return '刚刚';
  } else if (differenceInSeconds < 3600) { // 小于一个小时
      const minutes = Math.floor(differenceInSeconds / 60);
      return `${minutes}分钟前`;
  } else if (differenceInSeconds < 7200) { // 半个小时
      return '半个小时前';
  } else if (differenceInSeconds < 86400) { // 小于一天
      const hours = Math.floor(differenceInSeconds / 3600);
      return `${hours}小时前`;
  } else {
      const days = Math.floor(differenceInSeconds / 86400); // 计算天数
      return `${days}天前`;
  }
}


 export function formatDeadline(deadline) {
  const now = new Date();
  const deadlineDate = new Date(deadline);
  const differenceInMilliseconds = deadlineDate - now;
  
  if (differenceInMilliseconds < 0) {
      return '已过截止时间';
  }

  const differenceInSeconds = Math.floor(differenceInMilliseconds / 1000);
  const differenceInMinutes = Math.floor(differenceInSeconds / 60);
  const differenceInHours = Math.floor(differenceInMinutes / 60);
  const differenceInDays = Math.floor(differenceInHours / 24);

  if (differenceInDays === 0) {
      return `${differenceInHours}小时${differenceInMinutes % 60}分钟 截止`;
  } else if (differenceInDays === 1) {
      return `明天${differenceInHours % 24}小时${differenceInMinutes % 60}分钟 截止`;
  } else {
      return `${differenceInDays}天${differenceInHours % 24}小时${differenceInMinutes % 60}分钟 截止`;
  }
}

export const pay = (data) => {
  wx.requestPayment(data)
}
